package marchsoft.modules.four.admin.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.RequiredArgsConstructor;
import marchsoft.base.BasicServiceImpl;
import marchsoft.base.PageVO;
import marchsoft.modules.four.admin.entity.dto.SafeTypeDTO;
import marchsoft.modules.four.admin.mapper.SafeTypeMapper;
import marchsoft.modules.four.admin.service.SafeTypeService;
import marchsoft.modules.four.common.entity.SafeType;
import marchsoft.modules.four.common.mapper.MapperSafeType;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
@RequiredArgsConstructor
public class SafeTypeServiceImpl extends BasicServiceImpl<MapperSafeType, SafeType> implements SafeTypeService {
    private final SafeTypeMapper safeTypeMapper;

    @Override //分页条件查询安全分类
    public IPage<SafeType> queryAll1(PageVO pageVO, SafeTypeDTO safeTypeDTO) {
        IPage<SafeType> page = new Page<>(pageVO.getCurrent(), pageVO.getSize());
        QueryWrapper<SafeType> queryWrapper = new QueryWrapper<>();
        String safeTypeName = safeTypeDTO.getName();
        if (safeTypeName != null){
            Long id = safeTypeMapper.selectID(safeTypeName);
            if (0 != id){
                queryWrapper.eq("id",id);
            }
        }
        queryWrapper.orderByDesc("create_time");
        return page(page, queryWrapper);
    }

    @Override //查询所有安全分类名称
    public List<SafeType> selectAllNameSafeType() {
        return safeTypeMapper.selectAllSafeTypeName();
    }

    @Override //新增安全分类
    public void insertSafeType(SafeType safeType) {
        save(safeType);
    }

    @Override //跟新安全分类
    public void updateSafeType(SafeType safeType) {
        updateById(safeType);
    }

    @Override //根据id删除安全分类
    public void deleteSafeType(List<Integer> id) {
        removeByIds(id);
    }
}
